package srjava.messages;

import java.io.IOException;
import java.io.StringReader;

public class SrString implements Serializable {
	String str;

	public SrString() {
		str = "";
	}

	public SrString(String str) {
		super();
		this.str = str;
	}

	@Override
	public String serialize() {
		String s = str.length() + " " + str + " ";
		return s;
	}

	@Override
	public void deSerialize(StringReader s) throws IOException {
		char cbuf[];
		int size = IntString.parseInt(s);
		cbuf = new char[size];
		s.read(cbuf, 0, size);
		str = new String(cbuf);
		s.read();
	}

	@Override
	public boolean equals(Object arg0) {
		if (arg0.getClass() != getClass()) return false;
		if (((SrString)arg0).str.equals(str)) return true;
		return false;
	}

	@Override
	public String toString() {
		return str;
	}

}
